﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebTemplate.DAL.Entities;

namespace WebTemplate.DAL.Repositories
{
  public  class SemesterRepository
    {
      public List<Semester> Select( SemesterSearchCriteria item)
      {
          SqlConnection connection = new SqlConnection();
          connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

          SqlCommand command = new SqlCommand();
          command.Connection = connection;
          command.CommandText = "[Semester_Select]";
          command.CommandType = System.Data.CommandType.StoredProcedure;
          command.Parameters.AddWithValue("@Id", item.Id);
          command.Parameters.AddWithValue("@from", item.From);
          command.Parameters.AddWithValue("@to", item.To);
          command.Parameters.AddWithValue("@displayname", item.DisplayName);


          connection.Open();

          SqlDataReader reader = command.ExecuteReader();

          List<Semester> lst = new List<Semester>();
          while (reader.Read())
          {
              Semester obj = new Semester();

              obj.Id = reader.GetInt32(0);
              obj.To = reader.GetDateTime(1);
              obj.From = reader.GetDateTime(2);
              obj.DisplayName = reader.GetString(3);
     

              lst.Add(obj);
          }
          connection.Close();

          return lst;
      }
    }
}
